package com.cdks.wuxiu.api.component.aliyun;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import com.cdks.wuxiu.api.model.dto.CloudStorageDTO;
import com.cdks.wuxiu.api.util.AliyunOSSUtils;


/**
 * 云存储工具类
 */
@Slf4j
@Component
public class CloudStorage {
    private static int renameObject(String oldOjectName, String newOjectName)
    {
        if (oldOjectName != null)
        {
            AliyunOSSUtils.renameObject(AliyunConfig.CLOUD_END_POINT, AliyunConfig.CLOUD_BUCKET_NAME, oldOjectName, newOjectName);
        }

        return 0;
    }

    private static int deleteObject(String objectName)
    {
        log.error("deleteObject: " + objectName);

        if (objectName != null)
        {
            //AliyunOSSUtils.deleteObject(AliyunConfig.CLOUD_END_POINT, AliyunConfig.CLOUD_BUCKET_NAME, objectName);
        }

        return 0;
    }

    private static int deleteList(String prefix)
    {
        log.error("deleteList: " + prefix);

        //AliyunOSSUtils.deleteList(AliyunConfig.CLOUD_END_POINT, AliyunConfig.CLOUD_BUCKET_NAME, prefix);

        return 0;
    }

    public static CloudStorageDTO getAuthData()
    {
        return AliyunOSSUtils.getAuthData();
    }

    private static int renameFile(String prefix, String fileName)
    {
        renameObject("temp/" + fileName, prefix + "/" + fileName);

        return 0;
    }

    private static int deleteFile(String prefix, String fileName)
    {
        deleteObject(prefix + "/" + fileName);

        return 0;
    }

    public static int deleteUserData(Long userId) {
        deleteList("user/" + String.valueOf(userId));

        return 0;
    }

    public static int deleteUserFile(long userId, String fileName)
    {
        deleteFile("user/" + userId, fileName);

        return 0;
    }

    public static int deleteMoodFile(long userId, String fileName)
    {
        deleteFile("mood/" + userId, fileName);

        return 0;
    }

    public static int saveChatFile(long userId, String fileName)
    {
        renameFile("chat", + userId + "/" + fileName);

        return 0;
    }

    public static int deleteChatFile(long userId, String fileName)
    {
        deleteFile("chat/" + userId, fileName);

        return 0;
    }
}
